virtiofs: Add aggregate (multi-share) device support#3821
Open
damanm24 wants to merge 22 commits into
Open
Conversation
|
This PR modifies files containing For more on why we check whole files, instead of just diffs, check out the Rustonomicon |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR extends the virtiofs device to support an aggregate (multi-share) mode: a single virtio-fs instance can expose multiple independent host-folder shares by presenting a synthetic, read-only root directory whose named children map to each share, optionally advertised as FUSE submounts.
Changes:
- Add aggregate-mode virtio-fs implementation (
aggregate.rs) with synthetic root handling, child registry management, and (optional)FUSE_ATTR_SUBMOUNTadvertisement. - Refactor core
VirtioFsto support direct vs aggregate mode, per-share read-only enforcement, and inode namespacing across multiple volumes. - Extend resources/resolver plumbing with a new
VirtioFsBackend::Aggregatebackend and child descriptors.
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 8 comments.
Show a summary per file
| File | Description |
|---|---|
| vm/devices/virtio/virtiofs/src/util.rs | Update fuse_attr construction to initialize the new flags field. |
| vm/devices/virtio/virtiofs/src/section.rs | Update section-backed fs attribute construction to use flags instead of the old padding field. |
| vm/devices/virtio/virtiofs/src/resolver.rs | Add resolver support for VirtioFsBackend::Aggregate and populate children via add_child. |
| vm/devices/virtio/virtiofs/src/lib.rs | Introduce aggregate-aware VirtioFs internals, synthetic-root dispatch, per-inode read-only checks, and volume-id-aware inode mapping. |
| vm/devices/virtio/virtiofs/src/inode.rs | Add volume IDs + inode-number namespacing helpers to avoid cross-share inode collisions. |
| vm/devices/virtio/virtiofs/src/file.rs | Ensure readdir/readdirplus reports namespaced inode numbers consistent with lookup/getattr. |
| vm/devices/virtio/virtiofs/src/aggregate.rs | New aggregate-mode implementation: synthetic root, child registry, teardown gating, and unit tests. |
| vm/devices/virtio/virtio_resources/src/lib.rs | Add VirtioFsBackend::Aggregate and the VirtioFsAggregateChild Mesh payload. |
| vm/devices/support/fs/fuse/src/protocol.rs | Extend fuse_attr with flags and define FUSE_ATTR_SUBMOUNT/FUSE_ATTR_DAX. |
Comments suppressed due to low confidence (1)
vm/devices/virtio/virtiofs/src/lib.rs:571
- In aggregate mode the synthetic root inode (node_id == FUSE_ROOT_ID) is intentionally not stored in the inode map, so any unexpected call path that reaches
get_inode(FUSE_ROOT_ID)will emit a warning log about an “unknown inode”. This can be guest-triggerable (e.g. attempts to modify root) and lead to noisy logs. Consider suppressing the warning for the synthetic root ID.
fn get_inode(&self, node_id: u64) -> lx::Result<Arc<VirtioFsInode>> {
self.inner.inodes.read().get(node_id).ok_or_else(|| {
tracing::warn!(node_id, "request for unknown inode");
lx::Error::EINVAL
})
}
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Comment on lines
+63
to
+68
| /// Expose multiple host folders behind a single device, each as a named | ||
| /// child of a synthetic root. Lets one virtio-fs device (one tag, one | ||
| /// PCI/MMIO footprint) serve many shares. | ||
| Aggregate { | ||
| children: Vec<VirtioFsAggregateChild>, | ||
| }, |
Comment on lines
+63
to
+69
| /// Expose multiple host folders behind a single device, each as a named | ||
| /// child of a synthetic root. Lets one virtio-fs device (one tag, one | ||
| /// PCI/MMIO footprint) serve many shares. | ||
| Aggregate { | ||
| children: Vec<VirtioFsAggregateChild>, | ||
| }, | ||
| } |
Comment on lines
+242
to
+251
| fn insert_child_root_entry(&self, volume: Arc<VirtioFsVolume>) -> lx::Result<fuse_entry_out> { | ||
| let (inode, stat) = VirtioFsInode::new(volume, PathBuf::new())?; | ||
| let attr = inode.attr_from_stat(&stat); | ||
| let (_, node_id) = self.insert_inode(inode); | ||
| Ok(fuse_entry_out::new( | ||
| node_id, | ||
| ENTRY_TIMEOUT, | ||
| ATTRIBUTE_TIMEOUT, | ||
| attr, | ||
| )) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR adds an aggragate mode to the virtiofs device, so that a single virtiofs device can serve several, independent host-folder shares, instead of requiring one device per share. It does so by introducing a synthetic, read-only root directory whose named children are the host folders where each child is advertised to the guest with FUSE_ATTR_SUBMOUNT.
This allows us to use virtiofs in areas where MMIO/PCI device space is limited (i.e. WSL) and users frequently want to expose multiple shares.